<?php require_once('../Connections/shopcarda1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "member/company_member/admin_companym_list.php";
  $MM_redirectLoginFailed = "admin_login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_shopcarda1, $shopcarda1);
  
  $LoginRS__query=sprintf("SELECT account, pass FROM adminmember WHERE account=%s AND pass=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $shopcarda1) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<style type="text/css">
<!--
#index_up {
	width: 955px;
	background-image: url(../images/top_bg.png);
	height: 82px;
}
.style1 {	font-size: 14px;
	color: #666666;
	font-weight: bold;
}
.style2 {	color: #666666;
	font-size: 12px;
}
.style3 {	font-size: 13px;
	color: #FFFFFF;
}
.style8 {font-size: 7px; color: #FFFFFF; }
#index_contant {
	width: 955px;
	margin-right: 33px;
	margin-left: 33px;
}
#index_body {
	width: 955px;
}
#index_body_1 {
	margin-top: 100px;
	margin-right: 200px;
	margin-bottom: 100px;
	margin-left: 200px;
	width: 555px;
}
#login_body {
	margin-right: 10px;
	margin-bottom: 10px;
	margin-left: 10px;
}
#login_body_up {
	background-image: url(images/admin_login_text.png);
	height: 25px;
	margin-bottom: 10px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function savePass(nameusr,namepwd,valueusr,valuepwd,days) {
  var message = "";
  if (document.passForm.username.value == "" || document.passForm.password.value == "") {
    message = "Please insert both Username and Password.";
  }
  if (message.length > 0) {
    alert(message);
    return false;
  } else
  if (document.passForm.savepass.checked == true) {
    var time = new Date(Date.parse(Date()) + 86400000*days);
    document.cookie = nameusr + "=" + escape(valueusr) + "; expires=" + time.toUTCString();
    document.cookie = namepwd + "=" + escape(valuepwd) + "; expires=" + time.toUTCString();
  } else {
    document.cookie = nameusr + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 UTC";
    document.cookie = namepwd + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 UTC";
  }
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      var endstr = document.cookie.indexOf(";", j);
      if (endstr == -1) endstr = document.cookie.length;
      return unescape(document.cookie.substring(j, endstr));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return "";
}

function getPass(nameusr,namepwd) {
  if (getCookie(namepwd) != "undefined" && getCookie(namepwd) != "") {
    document.passForm.username.value = getCookie(nameusr);
    document.passForm.password.value = getCookie(namepwd);
    document.passForm.savepass.checked = true;
  }
}
//-->
</script>
</head>

<body>
<table width="1024" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id="index_contant">
      <div id="index_up"></div>
      <div id="index_body">
        <div id="index_body_1" onload="getPass('user','pass')">
          <table cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="3"><img src="../member/img/member_body_up.jpg" width="555" height="9" /></td>
            </tr>
            <tr>
              <td width="4" background="../member/img/member_body_left.jpg">&nbsp;</td>
              <td width="547"><div id="login_body_up"></div>
                <form ACTION="<?php echo $loginFormAction; ?>" method="POST" name="passForm" id="passForm"><div id="login_body">
                  <table width="527" cellpadding="10" cellspacing="0">
                    <tr>
                      <td width="165"><div align="right">帳號</div></td>
                      <td colspan="2">
                          <label>
                          <input type="text" name="username" id="username" />
                          </label>
                      </td>
                    </tr>
                    <tr>
                      <td><div align="right">密碼</div></td>
                      <td colspan="2">
                          <label>
                          <input type="text" name="password" id="password" />
                          </label>
                      </td>
                    </tr>
                    <tr>
                      <td align="right"><input name="savepass" type="checkbox" value="true" onclick="return savePass('user','pass',username.value,password.value,30)" />
                  <font face="Arial" size="1">記住密碼</font></td>
                      <td width="157">
                          <label></label>
                          <div align="right">
                            <input type="submit" name="Submit" value="登入" onclick="return savePass('user','pass',username.value,password.value,30)" />
                          </div>
                      </td>
                      <td width="143" class="style2">忘記密碼</td>
                    </tr>
                  </table>
                </div><div id=ttt></div></form></td>
              <td width="4" background="../member/img/member_body_right.jpg">&nbsp;</td>
            </tr>
            <tr>
              <td height="9" colspan="3"><img src="../member/img/member_body_down.jpg" width="555" height="9" /></td>
            </tr>
          </table>
        </div>
        </div>
      <div id="index_down">
        <table width="955" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="230" height="118" align="center"><a href="../index.html"><img width="200" height="66" alt="logo位置" style="background-color: #FF0000" /></a></td>
            <td width="10" align="center"><img src="file:///C|/Documents and Settings/Andy/My Documents/個人/控股公司/微衡科技有限公司/員購網站/images/end_Separateline1.png" width="1" height="80" /></td>
            <td width="715" valign="middle"><table width="715" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="40" valign="top" class="style2"><table border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="50" align="center" class="style2"></td>
                        <td>本平台中台灣各店家所銷售的商品或服務，都是由各該店家所銷售或提供。 | 電話 : 02-2275-3588 | 傳真 : 02-2275-3788<br/>
                          微衡科技　版權所有 ⓒ 2011 Microbalance. All Rights Reserved.</td>
                      </tr>
                  </table></td>
                </tr>
            </table></td>
          </tr>
        </table>
      </div>
    </div></td>
  </tr>
</table>
<div align="center"></div>
</body>
</html>
